# coding:utf-8
import json


class JsonDecoder:
    """"""

    def __init__(self, model=None):
        self.model = model

    def decode(self, s: str, **kwargs):
        data = json.loads(s, **kwargs)
        if self.model is None:
            return data
        instance = object.__new__(self.model)
        annotations = self.model.__annotations__
        if annotations:
            for name, v in annotations.items():
                setattr(instance, name, data.get(name))
        else:
            for key, value in data.items():
                if hasattr(instance, key):
                    setattr(instance, key, value)
        return instance
